//
//  HWGenerationOfFillingViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/2/26.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWGenerationOfFillingViewController.h"
#import "GenerationOfFillingModel.h"
#import "HWGenerationOfFillingCell.h" //本试图单于格


@interface HWGenerationOfFillingViewController ()<UITableViewDelegate,UITableViewDataSource>


@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *hederView;



@property(strong,nonatomic)UIView *beijingView;
@property(strong,nonatomic)UILabel *zongjieLabel;
@property(strong,nonatomic)UILabel *qinshuLabel;
@property(strong,nonatomic)UILabel  *gongbiLabel;



// 导航的三个控件
@property(strong,nonatomic) UIView *daohaView;
@property(strong,nonatomic) UIButton *fanhuiBut;
@property(strong,nonatomic) UILabel *biatiuLabe;


//存储的数据
@property(strong,nonatomic) NSMutableArray *dataMuArr;


@end

@implementation HWGenerationOfFillingViewController




-(UITableView *)mainaTableVie {
    
    if  (_mainaTableVie == nil) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, -StatusBarHeight, kScreenW, kScreenH+StatusBarHeight-TabbarSafeBottomMargin) style:UITableViewStyleGrouped];
        // _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-44) style:UITableViewStylePlain];
     //   _mainaTableVie.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = beijingyanSe;
        
       // _mainaTableVie.backgroundColor = [UIColor whiteColor];
    }
    
    
    return   _mainaTableVie;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self setupUI];
  //   [self setnavigation];
     [self setnavigation];
     
      // 发送网络请求
     [self sendNetworkRequest];
     
    
    
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES ];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
 
}

// 设置导航
- (void)setnavigation {
    
      self.view.backgroundColor = beijingyanSe;
    
       UIView *backeview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 44+StatusBarHeight)];
       backeview.backgroundColor = [UIColor clearColor];
       self.daohaView = backeview;
       
    //   backeview.alpha = 0.1;
       [self.view addSubview:backeview];
       
       UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
       button.frame = CGRectMake(10,StatusBarHeight+7, 30, 30);
       [button setImage:[UIImage imageNamed:@"fanhuibaiseanniu_ico"] forState:UIControlStateNormal];
       [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
       self.fanhuiBut = button;
       [self.view  addSubview:button];
       
       UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake((kScreenW-70)/2, StatusBarHeight+12, 70, 17)];
       textlabel.text = @"代充记录";
       textlabel.textAlignment =  NSTextAlignmentCenter;
       textlabel.textColor = [UIColor whiteColor];
       textlabel.textColor = [UIColor whiteColor];
       textlabel.font = [UIFont systemFontOfSize:16];
       self.biatiuLabe  = textlabel;
       [self.view  addSubview:textlabel];
       

}



- (void)buttonTap {
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
    
}


// 设置UI
- (void)setupUI {
    
    
    //添加headerView
    [self addTabelViewHeaderView];
    
    
    
    
    
}

//添加headeView

- (void)addTabelViewHeaderView {
    
    
    
    [self.view addSubview:self.mainaTableVie];
    
    self.hederView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 44+StatusBarHeight+128)];
    self.hederView.backgroundColor = RGB(85, 89, 234);
    self.mainaTableVie.tableHeaderView = self.hederView;
    
    
    
    self.beijingView = [[UIView alloc]initWithFrame:CGRectMake(0,  44+StatusBarHeight, kScreenW, 128)];
    self.beijingView.backgroundColor = RGB(85, 89, 234);
    [self.hederView addSubview: self.beijingView ];
    
    
    self.zongjieLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 22, 170, 17)];
    self.zongjieLabel .text = @"总代充金额(元)";
    self.zongjieLabel .textAlignment =  NSTextAlignmentLeft;
    self.zongjieLabel .textColor = [UIColor whiteColor];
    self.zongjieLabel .font = [UIFont systemFontOfSize:12];
    [self.beijingView   addSubview: self.zongjieLabel];
    
    
      self.qinshuLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, self.zongjieLabel.bottom+1, 170, 45)];
      self.qinshuLabel .text = @"600.02";
      self.qinshuLabel .textAlignment =  NSTextAlignmentLeft;
      self.qinshuLabel .textColor = [UIColor whiteColor];
      self.qinshuLabel .font = [UIFont systemFontOfSize:32];
      [self.beijingView   addSubview: self.qinshuLabel];
    
    
    
     self.gongbiLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, self.qinshuLabel.bottom+1, 280, 17)];
      self.gongbiLabel .text = @"共计 3 笔";
      self.gongbiLabel .textAlignment =  NSTextAlignmentLeft;
      self.gongbiLabel .textColor = [UIColor whiteColor];
      self.gongbiLabel .font = [UIFont systemFontOfSize:12];
      [self.beijingView   addSubview: self.gongbiLabel];
    
    
    
    
    
    
    
    

    
}



// 发送网络请求
- (void)sendNetworkRequest {
    
    
    
     
         NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
         NSString *uid =  [HWLocallyStoredData getLoginUserID];
         NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
         NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
           
        
        
        
         NSDictionary *parametes = @{      @"ios" : @"1",
                                       @"ct" : @"app",
                                        @"ac" : @"fuli_list",
                                        @"t" : tStr,
                                        @"uid":uid,
                                        @"sign" :signStrMd5
                                        };
        
        
            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                 

                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  if ([codeStr intValue] == 1) {
                 
                   
                      
                       NSLog(@"%@",response);
                      
                      self.qinshuLabel.text = [NSString stringWithFormat:@"%@",response[@"data"][@"money"]];
                      self.gongbiLabel.text =  [NSString stringWithFormat:@"共计 %@ 笔",response[@"data"][@"number"]];
                      
                      self.dataMuArr =  [GenerationOfFillingModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
                      [self.mainaTableVie reloadData];
                      
                        NSLog(@"%@",response);
                      
            
                      
                       
                  } else {
                      
                    [MBProgressHUD showError:response[@"message"]];
                                    
                
                      
                  }
                  
             
                  
              } failure:^(NSString *error) {
                 // [SVProgressHUD dismiss];
                  
                    [MBProgressHUD showSuccess:@"登录失败"];
                    [MBProgressHUD hideHUD];
                  
                  
              }];
        
    
    
    
    
    
    
    
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  self.dataMuArr.count;
    
    
    
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    
    HWGenerationOfFillingCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    
    if (!cell) {
        
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWGenerationOfFillingCell" owner:nil options:nil].firstObject;
        
        
        
        
    }
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    GenerationOfFillingModel *model = self.dataMuArr[indexPath.row];
    cell.dataModel = model;
    
    
    return  cell;
    
    
    
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  64;
    
    
}






@end
